const app = getApp()
const $ = app.globalData
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		colorArr: ["#EE2C2C", "#ff7070", "#EEC900", "#4876FF", "#ff6100",
			"#7DC67D", "#E17572", "#7898AA", "#C35CFF", "#33BCBA", "#C28F5C",
			"#FF8533", "#6E6E6E", "#428BCA", "#5cb85c", "#FF674F", "#E9967A",
			"#66CDAA", "#00CED1", "#9F79EE", "#CD3333", "#FFC125", "#32CD32",
			"#00BFFF", "#68A2D5", "#FF69B4", "#DB7093", "#CD3278", "#607B8B"
		]
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		var that = this
		let colorLen = this.data.colorArr.length
		var lat, lng
		wx.getLocation({
			type: 'wgs84',
			success: function(res) {
				// console.log(res);
				lat = res.latitude
				lng = res.longitude
				wx.request({
					url: $.AdminUrl + "/YApi/getShopList",
					data: {
						lat: lat,
						lng: lng
					},
					success: function(data) {
						var dataa = data.data.obj
						for (var i = 0; i < dataa.length; i++) {
							var random = Math.floor(Math.random() * colorLen + 0)
							dataa[i]['color'] = that.data.colorArr[random]
						}
						that.setData({
							business: dataa
						})
						console.log(dataa)
					}
				})
			}
		})
	},
	
	// 导航
	daohang:function(e){
		console.log(e)
		var a = e.currentTarget.dataset.a
		var b = e.currentTarget.dataset.b
		var c = e.currentTarget.dataset.c
		var d = e.currentTarget.dataset.d
		wx.navigateTo({
			url:"map/map?a="+a+"&b="+b+"&c="+c+"&d="+d
		})
	},
	// 跳转
	goushop:function(e){
		// 获取店铺id
		var shopid = e.currentTarget.dataset.id
		// 跳转
		wx.navigateTo({
			url:"../shopping/shop/shop?id="+shopid
		})
	},
	
	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function() {

	},


	// 分享转发
	onShareAppMessage: function() {
		var userinfo = wx.getStorageSync('userinfo')
		return {
			title: '优悦购生活管家',
			path: '/pages/index/index?userid=' + userinfo.loginname,
			success: (res) => {
				console.log("转发成功", res);
			},
			fail: (res) => {
				console.log("转发失败", res);
			}
		}
	}
})
